﻿/*
 * Created by SharpDevelop.
 * User: Chris
 * Date: 5/7/2013
 * Time: 6:50 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;

using ICSharpCode.SharpDevelop.Gui.OptionPanels;
using ICSharpCode.SharpDevelop.Project;

namespace Dither.Xna.Bindings.Gui
{
	/// <summary>
	/// Interaction logic for XnaGameStudioOptionsPanel.xaml
	/// </summary>
	public partial class XnaGameStudioOptionsPanel : ProjectOptionPanel
	{
		private const string ReachString = "Reach";
		private const string HiDefString = "HiDef";
		
		public static readonly DependencyProperty IsReachProperty = 
    		DependencyProperty.Register(
				"IsReach", typeof(bool), typeof(XnaGameStudioOptionsPanel));
		
		public static readonly DependencyProperty IsHiDefProperty = 
    		DependencyProperty.Register(
				"IsHiDef", typeof(bool), typeof(XnaGameStudioOptionsPanel));
		
		public bool IsReach{ 
			get{
				string propertyValue = XnaProfileProperty.Value;
				
				return propertyValue == ReachString;
			}
			set{
				SetXnaProfile(value);
				SetValue(IsReachProperty, value);
				SetValue(IsHiDefProperty, !value);
			}
		}
		
		public bool IsHiDef{ 
			get{
				string propertyValue = XnaProfileProperty.Value;
				
				return propertyValue == HiDefString;
			}
			set{
				SetXnaProfile(value);
				SetValue(IsReachProperty, !value);
				SetValue(IsHiDefProperty, value);
			}
		}
		
		private ProjectProperty<string> XnaProfileProperty{
			get { return GetProperty("XnaProfile", ReachString, PropertyStorageLocations.Base); }
		}
		
		public XnaGameStudioOptionsPanel()
		{
			InitializeComponent();
		}
		
		private void SetXnaProfile(bool isReach)
		{
			string xnaProfile = string.Empty;
			
			if (isReach){
				xnaProfile = ReachString;
			}
			else {
				xnaProfile = HiDefString;
			}
			
			XnaProfileProperty.Value = xnaProfile;
		}
		
		protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
		{
			if (e.Property == IsReachProperty){
				SetXnaProfile((bool)GetValue(IsReachProperty));
			}
			
			base.OnPropertyChanged(e);
		}
		
		private void ProjectOptionPanel_Loaded(object sender, RoutedEventArgs e)
		{
			bool isReach = (XnaProfileProperty.Value == ReachString);
			SetValue(IsReachProperty, isReach);
			SetValue(IsHiDefProperty, !isReach);
		}
	}
}